<template>
  <div class="app-container">
    <el-form
      :inline="true"
      ref="queryParams"
      :model="queryParams"
      :rules="rule"
      class="demo-form-inline"
    >
      <el-form-item label="ID" prop="userId">
        <el-input v-model="queryParams.userId" placeholder="id" />
      </el-form-item>
      <el-form-item label="开始日期" prop="startTime">
        <el-date-picker
          v-model="queryParams.startTime"
          type="datetime"
          placeholder="选择开始日期"
          value-format="yyyy-MM-dd HH:mm:ss"
        />
      </el-form-item>
      <el-form-item label="结束日期" prop="endTime">
        <el-date-picker
          v-model="queryParams.endTime"
          type="datetime"
          placeholder="选择结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <p>总计金额：{{ amount }}</p>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="序号" width="95">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column>
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="购买产品" align="center" prop="productName" />
      <el-table-column label="购买金额" align="center" prop="amount" />
      <el-table-column label="购买时间" align="center" prop="createTime" />
    </el-table>
    <div class="pagination">
      <el-pagination
        :current-page.sync="queryParams.pageNum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size.sync="queryParams.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="fetchData"
        @current-change="fetchData"
      />
    </div>
  </div>
</template>

<script>
import { dividendStatistics } from "@/api/table";
export default {
  components: {},
  data() {
    return {
      list: null,
      listLoading: false,
      total: 0,
      typeOptions: [
        { label: "虚拟货币", value: "usdt" },
        { label: "人民币", value: "rmb" },
      ],
      statusOptions: [
        { id: "processingTotal", label: "托管中总额" },
        { id: "residueTotal", label: "剩余待发放金额" },
      ],
      amount: 0,
      queryParams: {
        userId: "",
        pageNum: 1,
        pageSize: 10,
        startTime: "",
        endTime: "",
      },
      rule: {
        userId: [{ required: true, message: "请输入用户ID", trigger: "blur" }],
        startTime: [
          { required: true, message: "请选择开始时间", trigger: "change" },
        ],
        endTime: [
          { required: true, message: "请选择结束时间", trigger: "change" },
        ],
      },
    };
  },
  created() {},
  methods: {
    fetchData() {
      this.$refs.queryParams.validate((valid) => {
        if (!valid) return;
        this.listLoading = true;
        dividendStatistics(this.queryParams).then((response) => {
          this.list = response.data.records;
          this.listLoading = false;
          this.total = response.data.total;
          this.amount = response.message;
        });
      });
    },
    handleShowInfo(e) {
      this.$refs.showInfo.show(e);
    },
    setStateTxt(index) {
      let str = "";
      switch (Number(index)) {
        case 1:
          str = "审核中";
          break;
        case 2:
          str = "已完成";
          break;
        case 3:
          str = "失败";
          break;
      }
      return str;
    },
    setTypeTxt(index) {
      let str = "";
      switch (index) {
        case "progressing":
          str = "进行中";
          break;
        case "end":
          str = "已结束";
          break;
      }
      return str;
    },
    onSubmit() {
      this.queryParams.page = 1;
      this.fetchData();
    },
    reset() {
      this.queryParams = {
        hash: "",

        pageNum: 1,
        pageSize: 10,
        status: "",
      };
      this.fetchData();
    },
    handleAdd() {
      this.$refs.add.show();
    },
    handleEdit(e) {
      this.$refs.add.edit(e);
    },
    handleDel(e) {
      this.$confirm("此操作将删除公告, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          communityDelete(e).then((res) => {
            this.fetchData();
            this.$message({
              type: "success",
              message: "成功!",
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消操作",
          });
        });
    },
  },
};
</script>
